package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.seriver.YunSeriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 31629
 * @date 2025年09月09日 12:06
 */
@RestController
public class YunController {
    @Autowired
    private YunSeriver yunSeriver;
    @RequestMapping("s1")
    public JSONObject select1(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONArray data = new JSONArray();
        rest.put("data",data);


        List<Map<String, Objects>> maps = yunSeriver.select1();
        Map<String, Objects> map = maps.get(0);
        JSONObject row = new JSONObject();
        row.put("name","完成运输次数");
        row.put("value",map.get("cta"));

        JSONObject row1 = new JSONObject();
        row1.put("name","当日完成运输里程");
        row1.put("value",map.get("ctb"));

        JSONObject row2 = new JSONObject();
        row2.put("name","当日完成运输时长");
        row2.put("value",map.get("ctc"));

        data.add(row1);
        data.add(row);
        data.add(row2);
        return  rest;
    }

    @RequestMapping("s2")
    public JSONObject select2(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        List<Map<String, Objects>> maps = yunSeriver.select2();
        Map<String, Objects> map = maps.get(0);
        rest.put("data",map.get("cta"));


        return  rest;
    }

    @RequestMapping("s3")
    public JSONObject select3(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray columns = new JSONArray();
        JSONArray rows = new JSONArray();

        data.put("columns",columns);
        data.put("rows",rows);

        JSONObject col = new JSONObject();
        col.put("name","姓名");
        col.put("id","name");

        JSONObject col1 = new JSONObject();
        col1.put("name","机构里程");
        col1.put("id","cta");

        JSONObject col2 = new JSONObject();
        col2.put("name","完成次数");
        col2.put("id","ctb");


        JSONObject col3 = new JSONObject();
        col3.put("name","完成时长");
        col3.put("id","ctc");

        JSONObject col4 = new JSONObject();
        col4.put("name","平均时长");
        col4.put("id","ctd");

        columns.add(col);
        columns.add(col1);
        columns.add(col2);
        columns.add(col3);
        columns.add(col4);

        List<Map<String, Objects>> maps = yunSeriver.select3();
        for (Map<String, Objects> map : maps) {
            JSONObject row = new JSONObject();
            row.put("name",map.get("name"));
            row.put("cta",map.get("cta"));
            row.put("ctc",map.get("ctc"));
            row.put("ctd",map.get("ctd"));
            rows.add(row);
        }
        return  rest;
    }

    @RequestMapping("s4")
    public JSONObject select4(){
        JSONObject rest = new JSONObject();
        rest.put("status",0);
        rest.put("msg","");
        JSONObject data = new JSONObject();
        rest.put("data",data);

        JSONArray categories= new JSONArray();
        JSONArray series = new JSONArray();

        data.put("categories",categories);
        data.put("series",series);

        JSONObject ser = new JSONObject();
        ser.put("name","转运站");
        series.add(ser);

        List<Map<String, Objects>> maps = yunSeriver.select4();
        for (Map<String, Objects> map : maps) {
            categories.add(map.get("name"));
            JSONArray row = new JSONArray();
            row.add(map.get("cta"));
            ser.put("data",row);
        }


        return  rest;
    }
}
